package cn.topevery.garden.dal.dao.impl;

import cn.topevery.garden.dal.dao.PlaneDao;
import cn.topevery.garden.entity.po.Plane;
import cn.topevery.garden.entity.query.PlaneQuery;
import cn.topevery.garden.entity.vo.PlaneVO;
import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import hw.topevery.framework.entity.DbCsp;
import hw.topevery.framework.entity.KeyValue;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author code-generate
 * @date 2022-01-24
 */
@Repository
public class PlaneDaoImpl extends BaseDaoImpl<Plane> implements PlaneDao {
    @Override
    public <P extends DbCsp> List<Plane> getSearch(P para) {
        return null;
    }


    @Override
    public DataPager<PlaneVO> listPage(PlaneQuery query) {
        String table = "t_plane tp join t_section t on tp.c_section_id = t.c_section_id ";

        String columns = "tp.*,t.c_name sectionName";

        int pageIndex = query.pageIndex - 1;
        int pageSize = query.pageSize;

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("tp.c_id desc");
        sqlQueryMate
                .where(true, "tp.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(query.getPlaneType() != null, "tp.c_plane_type", ScriptConditionEnum.Eq, query.getPlaneType())
        ;

        return getDataPager(sqlQueryMate, pageSize, pageIndex, PlaneVO.class);
    }

    @Override
    public Plane getEntityByColumn(String key, String value) {
        KeyValue<String> map = new KeyValue<>();
        map.key = key;
        map.value = value;
        return getEntityByColumnEqValue(map);
    }
}
